package com.metagurukul.informer.utility;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class SendMail {
	
	/**
	 * method sending password to user's email
	 * @param recipientEmailId
	 * @param subject
	 * @param bodyText
	 * @return
	 */
	public boolean sendMail(String recipientEmailId, String subject, String bodyText) {
			
			Properties props = new Properties();
			props.put("mail.smtp.host", "smtp.gmail.com");
			props.put("mail.smtp.socketFactory.port", "465");
			props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
			props.put("mail.smtp.auth", "true");
			props.put("mail.smtp.port", "465");
			  	 
	 
			Session session = Session.getDefaultInstance(props,
				new javax.mail.Authenticator() {
					protected PasswordAuthentication getPasswordAuthentication() {
						return new PasswordAuthentication("metainformer@gmail.com","metainformerteamrocks");
					}
				});
	 
			try {
	 
				Message message = new MimeMessage(session);
				message.setFrom(new InternetAddress("metainformer@gmail.com"));
				message.setRecipients(Message.RecipientType.TO,InternetAddress.parse(recipientEmailId));
				message.setSubject(subject);	
				message.setText(bodyText);
				Transport.send(message);
	 
			} 
			catch (Exception e) {
				throw new RuntimeException(e);
			}
			
			return true;
			// TODO Auto-generated method stub
		}
}
